<?php
	require("../function.php");
	header('content-type:text/html;charset="utf-8"');
	global $con;
	$con= getconnect("china");
	$func = $_GET['func'];
	if(strcmp($func,"user")==0){
		user_judge();
	}elseif(strcmp($func,"pass1")==0){
		pass1_judge();
	}elseif(strcmp($func,"pass2")==0){
		pass2_judge();
	}elseif(strcmp($func,"email")==0){
		email_judge();
	}else{
		return;
	}
	function user_judge(){
		if($_POST['username']==""){
			echo "账号不能为空";
			return 0;
		}
		$usern=$_POST['username'];
		$sql4 = "SELECT * FROM users where username='".$usern."' and state=1 ;";
		$result = mysqli_query($GLOBALS['con'],$sql4);
		if(mysqli_num_rows($result)>0)
		{
			echo "此账号已被注册！";
		}else{
			echo 1;
		}
	}

	function pass1_judge(){
		if($_POST['password1']==""){
			echo "密码不能为空";
			return ;
		}
		if(strlen($_POST['password1'])<9){
			echo "密码长度不能少于9位";
		}
	}
	function pass2_judge(){
		if($_POST['password2']==""){
			echo "请确认您的密码！";
			return 0;
		}
		$pass1=$_POST['password1'];
		$pass2=$_POST['password2'];
		if(strcmp($pass1,$pass2)==0){
			return ;
		}else{
			echo "两次输入密码不同";
		}
	}
	function email_judge(){
		$path = "/^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*@([a-zA-Z0-9]+[-.])+([a-z]{2,5})$/";//邮箱
		if($_POST['email']==""){
			echo "邮箱不能为空！";
			return ;
		}
		if((preg_match($path,$_POST['email'])==0))
		{
			echo "邮箱格式不正确";
		}
	}

	
?>



